package expression;

import java.util.HashMap;
import java.util.LinkedList;

public class FnBoolNOT extends Fn implements FnBool {

	public FnBoolNOT() {}

	@Override
	protected boolean isAcceptableChild(Fn fn) {
		return (fn instanceof FnBool);
	}
	
	@Override
	protected boolean isAcceptableParam(Object o) {
		return (o instanceof Boolean);
	}
	
	@Override
	public int getNParam() {
		return 1;
	}
	
	@Override
	protected int precedence() {
		return 7;
	}

	@Override
	protected Object value(LinkedList<Object> param) {
		Object operand = param.getFirst();
		if (operand instanceof Boolean)
			return !((boolean) operand);
		return null;
	}

	@Override
	public String symbol() {
		return "!";
	}

	@Override
	protected String[] notation() {
		return new String[]
		{ "!", "", "" };
	}

	public static void main(String[] args) throws ExpressionException {
		FnBoolAND and = new FnBoolAND();
		and.addParam(new FnVariable("X"));
		and.addParam(new FnVariable("Y"));
		FnBoolNOT not = new FnBoolNOT();
		not.addParam(new FnVariable("Z"));
		and.addParam(not);
		System.out.println(and);

		HashMap<String, Object> varSub = new HashMap<>();
		varSub.put("X", true);
		varSub.put("Y", true);
		varSub.put("Z", false);
		System.out.println(and.evaluate(varSub));
	}

}
